package com.egg.demo.controller.web;

import com.egg.common.core.model.controller.WebController;
import com.egg.common.core.model.response.ResponseData;
import com.egg.common.spring.annotation.SensitiveAnnotation;
import com.egg.common.spring.enums.sensitive.SensitiveStrategyEnum;
import com.egg.common.util.IdGenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试数据脱敏控制器
 * <p>
 * 默认管理员不过滤
 * 需自行根据业务重写实现
 */
@Slf4j
@Api(tags = WebController.API_PREFIX + "数据脱敏")
@RestController
@RequestMapping("/sensitive")
public class WebSensitiveController extends WebController {

    @Data
    static class TestSensitive {

        /**
         * 身份证
         */
        @SensitiveAnnotation(strategy = SensitiveStrategyEnum.ID_CARD)
        private String idCard;

        /**
         * 电话
         */
        @SensitiveAnnotation(strategy = SensitiveStrategyEnum.PHONE)
        private String phone;

        /**
         * 地址
         */
        @SensitiveAnnotation(strategy = SensitiveStrategyEnum.ADDRESS)
        private String address;

        /**
         * 邮箱
         */
        @SensitiveAnnotation(strategy = SensitiveStrategyEnum.EMAIL)
        private String email;

        /**
         * 银行卡
         */
        @SensitiveAnnotation(strategy = SensitiveStrategyEnum.BANK_CARD)
        private String bankCard;

        private Long id;

    }

    /**
     * 测试数据脱敏
     */
    @ApiOperation(value = "查看")
    @GetMapping
    public ResponseData<TestSensitive> test() {
        TestSensitive testSensitive = new TestSensitive();
        testSensitive.setIdCard("210397198608215431");
        testSensitive.setPhone("17640125371");
        testSensitive.setAddress("北京市朝阳区某某四合院1203室");
        testSensitive.setEmail("17640125371@163.com");
        testSensitive.setBankCard("6226456952351452853");
        testSensitive.setId(IdGenUtil.longId());
        return ResponseData.success(testSensitive);
    }


}
